/*
 * dbm_pdb_manager.c
 *
 *  Created on: 2012-12-15
 *      Author: macro
 */
#include "pdb/policy_parse.h"
#include "pdb/policy_table.h"
#include "server/dbm_socket.h"
#include "pdb/dbm_policy_handler.h"
#include "pdb/dbm_pdb_manager.h"

int pdb_manager_init(){
	policy_init();
}
int send_policy(struct _policy_element* policy){
	int pkt_len = sizeof(policyMsg) + sizeof(policyMsgHeader);
	Packet_header* pkt = (Packet_header*)malloc(sizeof(Packet_header)+pkt_len);
	pkt->dest_module = PEA;
	pkt->sour_module = DBM;
	pkt->action = POLICY_EXECUTE;
	pkt->length = pkt_len;
	policyMsgHeader* msgHeader = (policyMsgHeader*)pkt->pkt;
	msgHeader->operation = policy->operation;
	msgHeader->pepversion = policy->version;
	policyMsg* msg = (policyMsg*)msgHeader->msg;
	msg->hello_interval = policy->value[0];
	msg->dead_interval = policy->value[1];
	struct packet policy_pkt;
	policy_pkt.sockfd = global_bm_sock;
	policy_pkt.head = (char*)pkt;
	policy_pkt.len = sizeof(Packet_header)+ pkt_len;
	dbm_send_packet(&policy_pkt);
}

